package main.com.liuchong.datadeal;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author: liuchong
 * @create: 2023/3/8 21:53
 * @description:
 */
public class CreateData {

    /**
     *
     * @param fileDirectory  结果输出目录
     * @param fileType  "EI"-主机；"CU"-银联
     * @param fileNum  生成文件数量
     * @param baseNum  文件行数
     * @throws IOException
     */
    public void createData(String fileDirectory, String fileType, int fileNum, int baseNum) throws IOException {
        BufferedWriter bw = null;
        for (int i = 1; i <= fileNum; i++) {
            File file = new File(fileDirectory + "/" + "file_" + fileType + String.format("_%03d.txt", i));
            bw = new BufferedWriter(new FileWriter(file));
            for (int j = 1; j <= baseNum; j++) {
                final String format = String.format("82022092023534318700000000000000010002B2022092000080%06d  ", (i - 1) * baseNum + j);
                final String str = format +
                        "2674660121 Z10002  C10002   Z1000200204";
                bw.write(str);
                bw.newLine();
                bw.flush();
            }
        }
        assert bw != null;
        bw.close();
    }
    public static void main(String[] args) throws IOException {
        long startTime = System.currentTimeMillis();
        new CreateData().createData("resource/CU", "CU", 38, 300);
        new CreateData().createData("resource/EI", "EI", 30, 300);
        long endTime = System.currentTimeMillis();
        System.out.println("程序运行时间： " + (endTime - startTime) + "ms");
    }
}
